﻿#region zh-CHS 2006 - 2007 DemoSoft 团队 | en 2006 - 2007 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the MMOSE(Massively Multiplayer Online Server Engine) for .NET.
//
//                              2006-2007 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Text;
using System.Linq;
using System.Threading;
using System.Collections.Generic;
#endregion

namespace Demo.Mmose.Core.Util
{
    /// <summary>
    /// 
    /// </summary>
    public static class ReaderWriterLockSlimEx
    {
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private static TimeSpan s_TimeSpan = TimeSpan.FromMilliseconds( 100 );
        #endregion

        #region zh-CHS 共有静态方法 | en Public Static Methods
        /// <summary>
        /// 
        /// </summary>
        /// <param name="readerWriterLockSlim"></param>
        /// <returns></returns>
        public static bool TryEnterReadLock( ReaderWriterLockSlim readerWriterLockSlim )
        {
            return readerWriterLockSlim.TryEnterReadLock( s_TimeSpan );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="readerWriterLockSlim"></param>
        /// <returns></returns>
        public static bool TryEnterWriteLock( ReaderWriterLockSlim readerWriterLockSlim )
        {
            return readerWriterLockSlim.TryEnterWriteLock( s_TimeSpan );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="readerWriterLockSlim"></param>
        /// <returns></returns>
        public static bool TryEnterUpgradeableReadLock( ReaderWriterLockSlim readerWriterLockSlim )
        {
            return readerWriterLockSlim.TryEnterUpgradeableReadLock( s_TimeSpan );
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="readerWriterLockSlim"></param>
        /// <returns></returns>
        public static void EnterWriteLock( ReaderWriterLockSlim readerWriterLockSlim )
        {
            readerWriterLockSlim.EnterWriteLock();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="readerWriterLockSlim"></param>
        /// <returns></returns>
        public static void ExitWriteLock( ReaderWriterLockSlim readerWriterLockSlim )
        {
            readerWriterLockSlim.ExitWriteLock();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="readerWriterLockSlim"></param>
        /// <returns></returns>
        public static void EnterReadLock( ReaderWriterLockSlim readerWriterLockSlim )
        {
            readerWriterLockSlim.EnterReadLock();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="readerWriterLockSlim"></param>
        /// <returns></returns>
        public static void ExitReadLock( ReaderWriterLockSlim readerWriterLockSlim )
        {
            readerWriterLockSlim.ExitReadLock();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="readerWriterLockSlim"></param>
        /// <returns></returns>
        public static void EnterUpgradeableReadLock( ReaderWriterLockSlim readerWriterLockSlim )
        {
            readerWriterLockSlim.EnterUpgradeableReadLock();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="readerWriterLockSlim"></param>
        /// <returns></returns>
        public static void ExitUpgradeableReadLock( ReaderWriterLockSlim readerWriterLockSlim )
        {
            readerWriterLockSlim.ExitUpgradeableReadLock();
        }
        #endregion
    }
}
#endregion